<template>
  <div class="app-container">
    <!--工具栏-->
    <crudOperation :permission="permission" />
    <div class="head-container">
      <el-dialog v-dialog-drag style="width: 80vm" title="搜索"   close-on-click-modal :visible.sync="crud.props.searchToggle"
                 width="70%">
        <el-form size="small" label-width="70px">
          <el-row :gutter="10">
<!--            <el-col :xs="24" :sm="12" :md="10" :lg="8" :xl="8">-->
<!--              <el-form-item label="业务日期">-->
<!--                <el-date-picker-->
<!--                  v-model="dataExtent"-->
<!--                  type="daterange"-->
<!--                  @change="getValue()"-->
<!--                  align="right"-->
<!--                  unlink-panels-->
<!--                  style="width: 100%"-->
<!--                  format="yyyy - MM - dd "-->
<!--                  value-format="yyyy-MM-dd"-->
<!--                  default-value-->
<!--                  range-separator=""-->
<!--                  start-placeholder="开始日期"-->
<!--                  end-placeholder="结束日期"-->
<!--                  :picker-options="pickerOptions">-->
<!--                </el-date-picker>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="审核日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.auditStartTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.auditEndTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="单据编号">
                <el-input v-model="query.orderCode" placeholder="输入编码进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="6" :lg="6" :xl="6">
              <el-form-item label="单据类型">
                <el-select v-model="orderType" collapse-tags multiple class="edit-input" placeholder="请选择单据类型" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.t_report_stock_flow_order_type"
                    :key="index"
                    multiple
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="往来单位">
                <el-input v-model="query.customerKeyword" placeholder="输入客户关键字进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="往来单位">
<!--                <zSelect multiple :value.sync="customerIds"  url="/api/dropDown/basCustomerList" style="width:  100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'code',label:'单位编码',width:'100'},{prop:'name',label:'往来单位名称',width: '280'}]"
                  :value.sync="query.customerIds"
                  placeholder="请选择往来单位"
                  url="/api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="商品">
                <el-input v-model="query.goodsKeyword" placeholder="输入商品关键字进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="商品">
                <table-select
                  :tableColumns="[{prop:'goodsCode',label:'商品编码',width:'100'},{prop:'goodsName',label:'商品名称',width: '280'}]"
                  labelKey="goodsName"
                  valueKey="goodsId"
                  :value.sync="query.goodsIds"
                  placeholder="请选择商品"
                  url="/api/dropDown/basGoodsListForAdd"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="商品分类">
                <treeselect
                  v-model="goodsTypeIds"
                  :options="areaList"
                  placeholder="商品"
                  style="width: 100%"
                  :normalizer="normalizer"
                  multiple
                  @input="val=>getNoStr(val,'areaList','goodsTypeIds')"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="商品品牌">
                <table-select
                  :tableColumns="[{prop:'code',label:'品牌编码',width:'100'},{prop:'name',label:'品牌名称',width: '280'}]"
                  :value.sync="query.goodsBrandIds"
                  placeholder="请选择品牌"
                  url="/api/dropDown/basGoodsBrandList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="单据备注">
                <el-input v-model="query.orderRemark" placeholder="输入商品进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="商品备注">
                <el-input v-model="query.goodsRemark" placeholder="输入商品进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
            <el-form-item label="单据状态">
              <el-select v-model="orderStatus" collapse-tags multiple class="edit-input" placeholder="请选择单据状态" style="width: 100%;">
                <el-option
                  v-for="(item,index) in dict.common_order_status"
                  :key="index"
                  multiple
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="仓库">
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.warehouseIds"
                  placeholder="请选择仓库"
                  url="/api/dropDown/basWarehouseList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="8">
              <el-form-item label="商贸公司">
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.fCustomerIds"
                  placeholder="请选择商贸公司"
                  url="/api/dropDown/basCustomerList"
                  :params="{type:2}"
                ></table-select>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row class="flex fow-reverse">
            <el-button class="filter-item"  size="mini" type="primary" @click="queryReport">搜索</el-button>
            <el-button class="filter-item" plain   size="mini" type="primary"
                       @click="resetQuery">重置</el-button>
          </el-row>
        </el-form>
      </el-dialog>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="业务日期">
            <el-input v-model="form.busDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据类型(1:发货单 2:销售退货入库 3:采购入库 4:采购出库 5:其他出库 6:其他入库 7:拆装单 8:调拨单 9:回瓶回箱)">
            <el-input v-model="form.orderType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据编号">
            <el-input v-model="form.orderCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="往来单位id">
            <el-input v-model="form.customerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="往来单位编码">
            <el-input v-model="form.customerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="往来单位名称">
            <el-input v-model="form.customerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库id">
            <el-input v-model="form.warehouseId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库编码">
            <el-input v-model="form.warehouseCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库名称">
            <el-input v-model="form.warehouseName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据备注">
            <el-input v-model="form.orderRemark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品id" prop="goodsId">
            <el-input v-model="form.goodsId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品编码">
            <el-input v-model="form.goodsCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品名称">
            <el-input v-model="form.goodsName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装类型(1:纸箱 2:塑箱 3:其他)">
            <el-input v-model="form.packageType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="条形码">
            <el-input v-model="form.barcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱装条形码">
            <el-input v-model="form.boxBarcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="助记符">
            <el-input v-model="form.helpSign" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="规格型号">
            <el-input v-model="form.model" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌id">
            <el-input v-model="form.goodsBrandId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌编码">
            <el-input v-model="form.goodsBrandCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌名称">
            <el-input v-model="form.goodsBrandName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类id">
            <el-input v-model="form.goodsTypeId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类编码">
            <el-input v-model="form.goodsTypeCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类名称">
            <el-input v-model="form.goodsTypeName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型id">
            <el-input v-model="form.goodsTagId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型编码">
            <el-input v-model="form.goodsTagCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型名称">
            <el-input v-model="form.goodsTagName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位id">
            <el-input v-model="form.boxUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位编码">
            <el-input v-model="form.boxUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位名称">
            <el-input v-model="form.boxUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数单位计量数">
            <el-input v-model="form.boxUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位id">
            <el-input v-model="form.mainUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位编码">
            <el-input v-model="form.mainUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位名称">
            <el-input v-model="form.mainUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位计量数">
            <el-input v-model="form.mainUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库数量">
            <el-input v-model="form.enterGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库箱数">
            <el-input v-model="form.enterBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库箱单位数量">
            <el-input v-model="form.enterBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库主单位数量">
            <el-input v-model="form.enterMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库含税金额">
            <el-input v-model="form.enterTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库未税金额">
            <el-input v-model="form.enterNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库税额">
            <el-input v-model="form.enterTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库数量">
            <el-input v-model="form.returnGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库箱数">
            <el-input v-model="form.returnBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库箱单位数量">
            <el-input v-model="form.returnBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库主单位数量">
            <el-input v-model="form.returnMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库含税金额">
            <el-input v-model="form.returnTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库未税金额">
            <el-input v-model="form.returnNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库税额">
            <el-input v-model="form.returnTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品备注">
            <el-input v-model="form.goodsRemark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加人id">
            <el-input v-model="form.createUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加人编码">
            <el-input v-model="form.createUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加人名称">
            <el-input v-model="form.createUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加时间">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核人id">
            <el-input v-model="form.auditUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核人编码">
            <el-input v-model="form.auditUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核人名称">
            <el-input v-model="form.auditUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审核时间">
            <el-input v-model="form.auditTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭人id">
            <el-input v-model="form.closeUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭人编码">
            <el-input v-model="form.closeUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭人名称">
            <el-input v-model="form.closeUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="关闭时间">
            <el-input v-model="form.closeTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收日期">
            <el-input v-model="form.acceptDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收人员id">
            <el-input v-model="form.acceptUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收人员编码">
            <el-input v-model="form.acceptUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收人员名称">
            <el-input v-model="form.acceptUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销日期">
            <el-input v-model="form.cancelDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销人员id">
            <el-input v-model="form.cancelUserId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销人员编码">
            <el-input v-model="form.cancelUserCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销人员名称">
            <el-input v-model="form.cancelUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        ></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="header"  @tabSave="saveHead" />
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" stripe border  :data="crud.data" size="small"
                style="width: 100%;"
                @header-dragend="changeColWidth"
                show-summary
                height="700"
                :summary-method="sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @contextmenu.native="showMenu"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 10px">
                <span v-if="item.prop === 'orderCode'" class="codeJump" @click="jump(scope.row)">
                  {{scope.row[`${item.prop}`]}}
                </span>
                <span v-else>{{scope.row[`${item.prop}`]}}</span>
              </span>
              <span v-else-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-else-if="item.type == 3" style="margin-left: 10px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>
<!--        <el-table-column v-if="columns.visible('busDate')" prop="busDate" label="业务日期">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.busDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('orderType')" prop="orderType" label="单据类型(1:发货单 2:销售退货入库 3:采购入库 4:采购出库 5:其他出库 6:其他入库 7:拆装单 8:调拨单 9:回瓶回箱)" />-->
<!--        <el-table-column v-if="columns.visible('orderCode')" prop="orderCode" label="单据编号" />-->
<!--        <el-table-column v-if="columns.visible('customerId')" prop="customerId" label="往来单位id" />-->
<!--        <el-table-column v-if="columns.visible('customerCode')" prop="customerCode" label="往来单位编码" />-->
<!--        <el-table-column v-if="columns.visible('customerName')" prop="customerName" label="往来单位名称" />-->
<!--        <el-table-column v-if="columns.visible('warehouseId')" prop="warehouseId" label="仓库id" />-->
<!--        <el-table-column v-if="columns.visible('warehouseCode')" prop="warehouseCode" label="仓库编码" />-->
<!--        <el-table-column v-if="columns.visible('warehouseName')" prop="warehouseName" label="仓库名称" />-->
<!--        <el-table-column v-if="columns.visible('orderRemark')" prop="orderRemark" label="单据备注" />-->
<!--        <el-table-column v-if="columns.visible('goodsId')" prop="goodsId" label="商品id" />-->
<!--        <el-table-column v-if="columns.visible('goodsCode')" prop="goodsCode" label="商品编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsName')" prop="goodsName" label="商品名称" />-->
<!--        <el-table-column v-if="columns.visible('packageType')" prop="packageType" label="包装类型(1:纸箱 2:塑箱 3:其他)" />-->
<!--        <el-table-column v-if="columns.visible('barcode')" prop="barcode" label="条形码" />-->
<!--        <el-table-column v-if="columns.visible('boxBarcode')" prop="boxBarcode" label="箱装条形码" />-->
<!--        <el-table-column v-if="columns.visible('helpSign')" prop="helpSign" label="助记符" />-->
<!--        <el-table-column v-if="columns.visible('model')" prop="model" label="规格型号" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandId')" prop="goodsBrandId" label="商品品牌id" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandCode')" prop="goodsBrandCode" label="商品品牌编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandName')" prop="goodsBrandName" label="商品品牌名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeId')" prop="goodsTypeId" label="商品分类id" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeCode')" prop="goodsTypeCode" label="商品分类编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeName')" prop="goodsTypeName" label="商品分类名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagId')" prop="goodsTagId" label="商品类型id" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagCode')" prop="goodsTagCode" label="商品类型编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagName')" prop="goodsTagName" label="商品类型名称" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitId')" prop="boxUnitId" label="箱单位id" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitCode')" prop="boxUnitCode" label="箱单位编码" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitName')" prop="boxUnitName" label="箱单位名称" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitCount')" prop="boxUnitCount" label="箱数单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitId')" prop="mainUnitId" label="主单位id" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCode')" prop="mainUnitCode" label="主单位编码" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitName')" prop="mainUnitName" label="主单位名称" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCount')" prop="mainUnitCount" label="主单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('enterGoodsCount')" prop="enterGoodsCount" label="入库数量" />-->
<!--        <el-table-column v-if="columns.visible('enterBoxCount')" prop="enterBoxCount" label="入库箱数" />-->
<!--        <el-table-column v-if="columns.visible('enterBoxNum')" prop="enterBoxNum" label="入库箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('enterMainNum')" prop="enterMainNum" label="入库主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('enterTaxAmount')" prop="enterTaxAmount" label="入库含税金额" />-->
<!--        <el-table-column v-if="columns.visible('enterNoTaxAmount')" prop="enterNoTaxAmount" label="入库未税金额" />-->
<!--        <el-table-column v-if="columns.visible('enterTax')" prop="enterTax" label="入库税额" />-->
<!--        <el-table-column v-if="columns.visible('returnGoodsCount')" prop="returnGoodsCount" label="出库数量" />-->
<!--        <el-table-column v-if="columns.visible('returnBoxCount')" prop="returnBoxCount" label="出库箱数" />-->
<!--        <el-table-column v-if="columns.visible('returnBoxNum')" prop="returnBoxNum" label="出库箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnMainNum')" prop="returnMainNum" label="出库主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnTaxAmount')" prop="returnTaxAmount" label="出库含税金额" />-->
<!--        <el-table-column v-if="columns.visible('returnNoTaxAmount')" prop="returnNoTaxAmount" label="出库未税金额" />-->
<!--        <el-table-column v-if="columns.visible('returnTax')" prop="returnTax" label="出库税额" />-->
<!--        <el-table-column v-if="columns.visible('goodsRemark')" prop="goodsRemark" label="商品备注" />-->
<!--        <el-table-column v-if="columns.visible('createUserId')" prop="createUserId" label="添加人id" />-->
<!--        <el-table-column v-if="columns.visible('createUserCode')" prop="createUserCode" label="添加人编码" />-->
<!--        <el-table-column v-if="columns.visible('createUserName')" prop="createUserName" label="添加人名称" />-->
<!--        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="添加时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.createTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('auditUserId')" prop="auditUserId" label="审核人id" />-->
<!--        <el-table-column v-if="columns.visible('auditUserCode')" prop="auditUserCode" label="审核人编码" />-->
<!--        <el-table-column v-if="columns.visible('auditUserName')" prop="auditUserName" label="审核人名称" />-->
<!--        <el-table-column v-if="columns.visible('auditTime')" prop="auditTime" label="审核时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.auditTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('closeUserId')" prop="closeUserId" label="关闭人id" />-->
<!--        <el-table-column v-if="columns.visible('closeUserCode')" prop="closeUserCode" label="关闭人编码" />-->
<!--        <el-table-column v-if="columns.visible('closeUserName')" prop="closeUserName" label="关闭人名称" />-->
<!--        <el-table-column v-if="columns.visible('closeTime')" prop="closeTime" label="关闭时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.closeTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('acceptDate')" prop="acceptDate" label="验收日期">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.acceptDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('acceptUserId')" prop="acceptUserId" label="验收人员id" />-->
<!--        <el-table-column v-if="columns.visible('acceptUserCode')" prop="acceptUserCode" label="验收人员编码" />-->
<!--        <el-table-column v-if="columns.visible('acceptUserName')" prop="acceptUserName" label="验收人员名称" />-->
<!--        <el-table-column v-if="columns.visible('cancelDate')" prop="cancelDate" label="核销日期">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.cancelDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('cancelUserId')" prop="cancelUserId" label="核销人员id" />-->
<!--        <el-table-column v-if="columns.visible('cancelUserCode')" prop="cancelUserCode" label="核销人员编码" />-->
<!--        <el-table-column v-if="columns.visible('cancelUserName')" prop="cancelUserName" label="核销人员名称" />-->
<!--        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />-->
<!--        <el-table-column v-permission="['admin','reportStockFlow:edit','reportStockFlow:del']" label="操作" width="150px" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--              :data="scope.row"-->
<!--              :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
<!--      <el-pagination-->
<!--        :current-page.sync="query.page"-->
<!--        :page-size.sync="query.size"-->
<!--        :total="crud.page.total"-->
<!--        layout="prev, pager, next"-->
<!--        style="margin-top: 8px; position: fixed;bottom:35px"-->
<!--        @size-change="onGet"-->
<!--        @current-change="onGet"-->
<!--      />-->
    </div>
  </div>
</template>

<script>
import crudReportStockFlow from '@/api/erp/reportStockFlow'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import Treeselect from '@riophae/vue-treeselect'
import {get} from '@/api/erp/reportStockFlow'
import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
// import {tablemixins} from "@/mixins/tablemixins";
import { manyTableMixin } from "../../../../mixins/manyTableMixin";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";
// crud交由presenter持有
const defaultCrud = CRUD({ title: '库存流水报表',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false

  },
  queryOnPresenterCreated:false,
  url: 'api/reportStockFlow', sort: 'auditTime desc',
  crudMethod: { ...crudReportStockFlow }})
const defaultForm = { busDate: null, orderType: null, orderCode: null, customerId: null, customerCode: null, customerName: null, warehouseId: null, warehouseCode: null, warehouseName: null, orderRemark: null, goodsId: null, goodsCode: null, goodsName: null, packageType: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, boxUnitId: null, boxUnitCode: null, boxUnitName: null, boxUnitCount: null, mainUnitId: null, mainUnitCode: null, mainUnitName: null, mainUnitCount: null, enterGoodsCount: null, enterBoxCount: null, enterBoxNum: null, enterMainNum: null, enterTaxAmount: null, enterNoTaxAmount: null, enterTax: null, returnGoodsCount: null, returnBoxCount: null, returnBoxNum: null, returnMainNum: null, returnTaxAmount: null, returnNoTaxAmount: null, returnTax: null, goodsRemark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, auditUserId: null, auditUserCode: null, auditUserName: null, auditTime: null, closeUserId: null, closeUserCode: null, closeUserName: null, closeTime: null, acceptDate: null, acceptUserId: null, acceptUserCode: null, acceptUserName: null, cancelDate: null, cancelUserId: null, cancelUserCode: null, cancelUserName: null, id: null,
}
export default {
  name: 'ReportStockFlow',
  components: { pagination, crudOperation, rrOperation, udOperation, Treeselect,jTableColumnConfig },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,manyTableMixin],
  dicts:['t_report_stock_flow_order_type','common_order_status'],
  mounted() {
    this.crud.props.searchToggle =false
  },
  created() {
    getBasGoodsTypeTree({size:999}).then(res=>{
      this.areaList = res.data
    })
  },
  data() {
    return {
      total:0,
      customerIds:[],
      areaList:[],
      goodsTypeIds:[],
      goodsBrandIds:[],
      orderType:[],
      orderStatus:[],
      fCustomerIds:[],
      jumpPath:[
        '/ware/wareSalesInvoiceDetail/',
        '/ware/wareSalesReturnDetail/',
        '/ware/wareBuyEnterDetail/',
        '/ware/wareBuyReturnDetail/',
        '/ware/wareOtherOutDetail/',
        '/ware/wareOtherEnterDetail/',
        '/ware/wareSplitOrderDetail/',
        '/ware/wareAllotDetail/',
        '/ware/wareReturnBottleBoxDetail/',
      ],
      goodsIds:[],
      warehouseIds:[],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },

      permission: {
        add: ['admin', 'reportStockFlow:add'],
        edit: ['admin', 'reportStockFlow:edit'],
        del: ['admin', 'reportStockFlow:del'],
        import: ['admin', 'reportStockFlow:import'],
        export: ['admin', 'reportStockFlow:export'],
        copy: ['admin', 'reportStockFlow:copy'],
        upload: ['admin', 'reportStockFlow:upload'],
        download: ['admin', 'reportStockFlow:download'],
      },
      rules: {
        goodsId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ]
      },
      dataExtent:[],
    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    sumRow({ columns, data }){
      const sums = []
      for (let i in  columns) {
        if (['returnGoodsCount','returnBoxCount','returnTaxAmount','returnNoTaxAmount','returnTax',
          'enterGoodsCount','enterBoxCount','enterTaxAmount','enterNoTaxAmount','enterTax'].includes(columns[i].property)) {
          let selectSum = 0
          this.$refs.table.selection.forEach(item => {
            selectSum += item[columns[i].property]
          })
          sums[i] = <p>{selectSum}
          <hr/>
          {this.crud.summary[columns[i].property] || 0}</p>
        }
        sums[0] = <p>选中
        <hr/>
        合计</p>
      }
      return sums
    },
    getValue(e){
      this.query.startDate = this.dataExtent[0]
      this.query.endDate = this.dataExtent[1]
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
    onGet(){
      const that =this
      let {page,size} = this.crud.page
      page = 1
      get({...this.query,page,size}).then(res=>{
        that.crud.data = res.data.content
        that.crud.page.total = res.data.totalElements
        that.crud.summary = res.data.summary
        console.log(that.total)
      })
    },
    jump(row){
      this.$router.push({path:this.jumpPath[Number(row.orderType)-1]+row.orderId})
    },
    resetQuery(){
      this.query = {
        customerIds:null,
          customerKeyword:'',
          endDate:null,
          orderCode:null,
          orderType: null,
          goodsKeyword:'',
          goodsTypeIds:null,
          goodsBrandIds:null,
          orderRemark:'',
          goodsRemark: '',
          orderStatus: null,
          warehouseIds: null,
          startDate:null,
          fCustomerIds: null,
          page:1,
          size:10,
        sort:'auditTime,desc'
      }
      this.goodsTypeIds = []
      this.orderType  = []
      this.goodsBrandIds = []
      this.orderStatus  = []
      this.warehouseIds = []
      this.dataExtent = []
      this.customerIds = []
      this.fCustomerIds= []
      this.$forceUpdate()
      this.onGet()
    },
    getNoStr(val,type,prop){
      let str = ''
      val.forEach(item=>{
        const itemNode = this.getTreeName(this[type],item)
        str = this.getNode(itemNode,str)
      })
      this.query[prop] = str
    },
    getTreeName(treeList,id){
      let _this=this
      for (let i = 0; i < treeList.length; i++) {
        let treeItem=treeList[i]
        if(treeItem.id===id){
          return treeItem
        }else{
          if(treeItem.children && treeItem.children.length>0){
            let res=_this.getTreeName(treeItem.children,id)
            if(res){
              return res
            }
          }
        }
      }
    },
    getNode(node,str){
      if (node.children){
        for (let i =0;i<node.children.length;i++){
          str = this.getNode(node.children[i],str)
        }
      }
      return str+=node.id+ ','
    },
    queryReport(){
      this.query.orderType = this.orderType.length?this.orderType.join(','):''
      // this.query.goodsBrandIds = this.goodsBrandIds.length?this.goodsBrandIds.join(','):''
      this.query.orderStatus = this.orderStatus.length?this.orderStatus.join(','):''
      // this.query.warehouseIds= this.warehouseIds.length?this.warehouseIds.join(','):''
      // this.query.customerIds = this.customerIds.length?this.customerIds.join(','):''
      // this.query.goodsIds = this.goodsIds.length?this.goodsIds.join(','):''
      // this.query.fCustomerIds = this.fCustomerIds.length?this.fCustomerIds.join(','):''
      this.onGet()
      this.crud.props.searchToggle = false
    }
  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .flex{
    display: flex;
  }
  .fow-reverse{
    flex-direction: row-reverse;
  }
  .codeJump{
    background-image:-webkit-linear-gradient(left,#6b85dd,#ff00fb);
    -webkit-background-clip:text;
    -webkit-text-fill-color:transparent;
    cursor: pointer;
  }
</style>
